'use strict';
const { checkTable } = require('../tools');

module.exports = (app) => {
  const { STRING, INTEGER } = app.Sequelize;

  const name = 'e_user';

  const User = app.model.define(
    name,
    {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      username: {
        type: STRING(20),
        allowNull: false,
        unique: true,
        validate: {
          notEmpty: true,
          len: [4, 8],
        },
      },
      password: {
        type: STRING(100),
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      avatar: {
        type: STRING(255),
        allowNull: true,
      },
    },
    {
      paranoid: true,
    }
  );

  checkTable(app, name);

  return User;
};
